package com.example.musicproject_b.Controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.b_pojo.BMenu;
import com.example.common.utils.Resultb;
import com.example.service.bMuneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/B_admin/rolespermision")
public class RolesPermisionController {

    @Autowired
    private bMuneService bMuneService;

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/8/23 11:27
     *      角色权限列表（查询全部不包含逻辑删除）
     */
    @RequestMapping("/alllist")
    public Resultb alllist(int pageNum, int pageSize) {
        Page<BMenu> allrole = bMuneService.getAllmenu(pageNum, pageSize);
        if (allrole.getRecords().size() > 0) {
            return Resultb.success(allrole);
        }
        return Resultb.error();
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/8/23 11:27
     *      角色权限列表（包含逻辑删除）
     */
    @RequestMapping("/hasdelectlist")
    public Resultb hasdelectlist(int pageNum, int pageSize) {
        Page<BMenu> allrole = bMuneService.gethasdelectmenu(pageNum, pageSize);
        if (allrole.getRecords().size() > 0) {
            return Resultb.success(allrole);
        }
        if (allrole.getRecords().size() == 0){
            return Resultb.success();
        }
        return Resultb.error();
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/4 16:31
     * 根据id 查询角色权限
     */
    @RequestMapping("/getmenu")
    public Resultb getmenu(Long id) {
        BMenu menu = bMuneService.getMenu(id);
        if (menu != null) {
            return Resultb.success(menu);
        }
        if (menu == null){
            return Resultb.success();
        }
        return Resultb.error();
    }



    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/8/23 11:28
     *      禁用和启用角色权限
     */
    @RequestMapping("/startandstopmenu")
    public Resultb startmenu(Long id) {
        boolean startandstopmenu = bMuneService.startandstopmenu(id);
        if (startandstopmenu) {
            return Resultb.success();
        }
        return Resultb.error();
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/11 12:16
     * 彻底删除记录
     */
    @RequestMapping("/deletemenu")
    public Resultb deletemenu(Long id) {
        boolean deletemenu = bMuneService.deletemenu(id);
        if (deletemenu) {
            return Resultb.success();
        }
        return Resultb.error();
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/8/23 11:29
     *      添加角色权限
     */
    @RequestMapping("/addmenu")
    public Resultb addmenu(@RequestBody BMenu bMenu) {
        boolean addmenu = bMuneService.addmenu(bMenu);
        if (addmenu) {
            return Resultb.success("添加成功！");
        }
        return Resultb.error("添加失败！");
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/8/23 11:30
     *      修改角色权限(包含逻辑删除)
     */
    @RequestMapping("/updatemenu")
    public Resultb updatemenu(@RequestBody BMenu bMenu) {
        boolean updatemenu = bMuneService.updatemenu(bMenu);
        if (updatemenu) {
            return Resultb.success();
        }
        return Resultb.error();
    }

}
